import React, { Component } from 'react'
import dayjs from 'dayjs'
export default function CommentList({ comments, active }) {
  function dealTime(time) {
    return dayjs(time).format('YYYY-MM-DD')
  }
  const newData = [...comments]
  if (active === 'time') {
    newData.sort((a, b) => new Date(a.time) - new Date(b.time))
    console.log(newData)
  } else {
    newData.sort((a, b) => a.id - b.id)
  }
  return (
    <ul className="comm-list">
      {newData.map(item => (
        <li key={item.id} className="comm-item">
          <div
            className="avatar"
            style={{ backgroundImage: `url(${item.avatar})` }}
          ></div>
          <div className="info">
            <p className="name vip">
              {item.name}
              <img
                alt=""
                src="https://gw.alicdn.com/tfs/TB1c5JFbGSs3KVjSZPiXXcsiVXa-48-48.png"
              />
            </p>
            <p className="time">
              {dealTime(item.time)} <span className="del">删除</span>
            </p>
            <p>{item.content}</p>
          </div>
        </li>
      ))}
    </ul>
  )
}
